//
// Created by shirley on 2024/12/23.
//

#ifndef DENSEMATRIX_H
#define DENSEMATRIX_H
#include <iostream>
#include <memory>
#include <vector>


using namespace std;
class DenseSolver;
class DenseMatrix {

    private:
        vector<vector<double>> data;
        vector<DenseMatrix> blocks;
        size_t rows;
        size_t cols;

    public:
        // 构造函数
        DenseMatrix();
        DenseMatrix(size_t rows, size_t cols, double initValue = 0.0);
        DenseMatrix(const DenseMatrix& matrix);
        DenseMatrix(size_t rows, size_t cols,double *data);
        DenseMatrix(const DenseMatrix& matrix, size_t startRow, size_t startCol, size_t numRows, size_t numCols);
        // 获取行数
        size_t getRows() const {
            return rows;
        }

        // 获取列数
        size_t getCols() const {
            return cols;
        }
        //获取所有矩阵元素
        vector<vector<double>> GetData() const{
            return data;
        }
        //获取矩阵指定行元素
        vector<double> GetData_r(int row) const{
            vector<double> datas(cols,0.0);
            for (int i = 0; i < cols; ++i)
            {
                datas[i] = data[row][i];
            }
            return datas;
        }
        //获取矩阵指定列元素
        vector<double> GetData_c(int col) const{
            vector<double> datas(rows,0.0);
            for (int i = 0; i < rows; ++i)
            {
                datas[i] = data[i][col];
            }
            return datas;
        }
        // 设置矩阵元素
        void setValue(size_t row, size_t col, double value);

        // 获取特定矩阵元素
        double getValue(size_t row, size_t col) const;

        //获取分块矩阵
        vector<DenseMatrix> GetBlocks() const;

        //交换指定位置元素
        void swap_(size_t row1, size_t col1, size_t row2, size_t col2);

        // 矩阵加法
        DenseMatrix operator+(const DenseMatrix& other) const;

        // 矩阵乘法
        DenseMatrix operator*(const DenseMatrix& other) const;

        //矩阵分块
        void block_(size_t size);

        friend class DenseSolver;
        // 输出矩阵
        void print() const;
};



#endif //DENSEMATRIX_H
